# delimit ;

clear all;
clear matrix;
set mem 800m;
set more off;

*add your path here:;
cd "C:\Users\jamesCabral\OneDrive - DAZ\CGH_Empirical_Replication";

cd "data\ATUS_AHTUS_raw_data\ATUS_ALL";

************************************************************************************************************;
* using all available data 2003-2019 uncomment the following lines;
use ATUS_ALL_FINAL;

cd "..\..\ATUS_AHTUS_state_datasets";

drop twoyear;

gen age1=0;
replace age1=1 if age>=18 & age<=27;
gen age2=0;
replace age2=1 if age>=28 & age<=37;
gen age3=0;
replace age3=1 if age>=38 & age<=47;
gen age4=0;
replace age4=1 if age>=48 & age<=57;
gen age5=0;
replace age5=1 if age>=58 & age<=65;
gen educ1=0;
replace educ1=1 if grade<12;
gen educ2=0;
replace educ2=1 if grade==12;
gen educ3=0;
replace educ3=1 if grade>12 & grade<16;
gen educ4=0;
replace educ4=1 if grade>=16;

drop if age>65;
drop if age<18;
drop if other>0;

************************************************************************************************************;
tabout quarter if year==2003            [aw=weight_adj] using state_dataset_ALLUS_temp.xls, replace format(8) ptotal(none) lines (none)                            sum cells(N work_paper mean year mean quarter mean male mean age mean age1 mean age2 mean age3 mean age4 mean age5 mean educ1 mean educ2 mean educ3 mean educ4 mean spouse_emp mean married mean black mean hv_child mean num_child mean grade mean working mean unemp mean retired mean disabled mean student mean homemaker  mean work_paper mean worka_paper mean worku_paper mean leisure_paper mean ep_paper mean sleeping_paper mean esp_paper mean leisure_noesp_paper mean tv_paper mean otherleisure_paper mean socializing_paper mean home_paper mean homeproduction_paper mean homeown_paper mean shopping_paper mean othercare_paper mean childcare_paper mean other_paper mean education_paper mean civic_paper mean ownmedical_paper mean unclassified_paper) show(none);


tabout quarter if year==2004           [aw=weight_adj] using state_dataset_ALLUS_temp.xls, append  format(8) h1(nil) h2(nil) h3(nil) ptotal(none) lines (none)    sum cells(N work_paper mean year mean quarter mean male mean age mean age1 mean age2 mean age3 mean age4 mean age5 mean educ1 mean educ2 mean educ3 mean educ4 mean spouse_emp mean married mean black mean hv_child mean num_child mean grade mean working mean unemp mean retired mean disabled mean student mean homemaker  mean work_paper mean worka_paper mean worku_paper mean leisure_paper mean ep_paper mean sleeping_paper mean esp_paper mean leisure_noesp_paper mean tv_paper mean otherleisure_paper mean socializing_paper mean home_paper mean homeproduction_paper mean homeown_paper mean shopping_paper mean othercare_paper mean childcare_paper mean other_paper mean education_paper mean civic_paper mean ownmedical_paper mean unclassified_paper) show(none);

tabout quarter if year==2005           [aw=weight_adj] using state_dataset_ALLUS_temp.xls, append  format(8) h1(nil) h2(nil) h3(nil) ptotal(none) lines (none)    sum cells(N work_paper mean year mean quarter mean male mean age mean age1 mean age2 mean age3 mean age4 mean age5 mean educ1 mean educ2 mean educ3 mean educ4 mean spouse_emp mean married mean black mean hv_child mean num_child mean grade mean working mean unemp mean retired mean disabled mean student mean homemaker  mean work_paper mean worka_paper mean worku_paper mean leisure_paper mean ep_paper mean sleeping_paper mean esp_paper mean leisure_noesp_paper mean tv_paper mean otherleisure_paper mean socializing_paper mean home_paper mean homeproduction_paper mean homeown_paper mean shopping_paper mean othercare_paper mean childcare_paper mean other_paper mean education_paper mean civic_paper mean ownmedical_paper mean unclassified_paper) show(none);

tabout quarter if year==2006           [aw=weight_adj] using state_dataset_ALLUS_temp.xls, append  format(8) h1(nil) h2(nil) h3(nil) ptotal(none) lines (none)    sum cells(N work_paper mean year mean quarter mean male mean age mean age1 mean age2 mean age3 mean age4 mean age5 mean educ1 mean educ2 mean educ3 mean educ4 mean spouse_emp mean married mean black mean hv_child mean num_child mean grade mean working mean unemp mean retired mean disabled mean student mean homemaker  mean work_paper mean worka_paper mean worku_paper mean leisure_paper mean ep_paper mean sleeping_paper mean esp_paper mean leisure_noesp_paper mean tv_paper mean otherleisure_paper mean socializing_paper mean home_paper mean homeproduction_paper mean homeown_paper mean shopping_paper mean othercare_paper mean childcare_paper mean other_paper mean education_paper mean civic_paper mean ownmedical_paper mean unclassified_paper) show(none);

tabout quarter if year==2007           [aw=weight_adj] using state_dataset_ALLUS_temp.xls, append  format(8) h1(nil) h2(nil) h3(nil) ptotal(none) lines (none)    sum cells(N work_paper mean year mean quarter mean male mean age mean age1 mean age2 mean age3 mean age4 mean age5 mean educ1 mean educ2 mean educ3 mean educ4 mean spouse_emp mean married mean black mean hv_child mean num_child mean grade mean working mean unemp mean retired mean disabled mean student mean homemaker  mean work_paper mean worka_paper mean worku_paper mean leisure_paper mean ep_paper mean sleeping_paper mean esp_paper mean leisure_noesp_paper mean tv_paper mean otherleisure_paper mean socializing_paper mean home_paper mean homeproduction_paper mean homeown_paper mean shopping_paper mean othercare_paper mean childcare_paper mean other_paper mean education_paper mean civic_paper mean ownmedical_paper mean unclassified_paper) show(none);

tabout quarter if year==2008           [aw=weight_adj] using state_dataset_ALLUS_temp.xls, append  format(8) h1(nil) h2(nil) h3(nil) ptotal(none) lines (none)    sum cells(N work_paper mean year mean quarter mean male mean age mean age1 mean age2 mean age3 mean age4 mean age5 mean educ1 mean educ2 mean educ3 mean educ4 mean spouse_emp mean married mean black mean hv_child mean num_child mean grade mean working mean unemp mean retired mean disabled mean student mean homemaker  mean work_paper mean worka_paper mean worku_paper mean leisure_paper mean ep_paper mean sleeping_paper mean esp_paper mean leisure_noesp_paper mean tv_paper mean otherleisure_paper mean socializing_paper mean home_paper mean homeproduction_paper mean homeown_paper mean shopping_paper mean othercare_paper mean childcare_paper mean other_paper mean education_paper mean civic_paper mean ownmedical_paper mean unclassified_paper) show(none);

tabout quarter if year==2009           [aw=weight_adj] using state_dataset_ALLUS_temp.xls, append  format(8) h1(nil) h2(nil) h3(nil) ptotal(none) lines (none)    sum cells(N work_paper mean year mean quarter mean male mean age mean age1 mean age2 mean age3 mean age4 mean age5 mean educ1 mean educ2 mean educ3 mean educ4 mean spouse_emp mean married mean black mean hv_child mean num_child mean grade mean working mean unemp mean retired mean disabled mean student mean homemaker  mean work_paper mean worka_paper mean worku_paper mean leisure_paper mean ep_paper mean sleeping_paper mean esp_paper mean leisure_noesp_paper mean tv_paper mean otherleisure_paper mean socializing_paper mean home_paper mean homeproduction_paper mean homeown_paper mean shopping_paper mean othercare_paper mean childcare_paper mean other_paper mean education_paper mean civic_paper mean ownmedical_paper mean unclassified_paper) show(none);

tabout quarter if year==2010           [aw=weight_adj] using state_dataset_ALLUS_temp.xls, append  format(8) h1(nil) h2(nil) h3(nil) ptotal(none) lines (none)    sum cells(N work_paper mean year mean quarter mean male mean age mean age1 mean age2 mean age3 mean age4 mean age5 mean educ1 mean educ2 mean educ3 mean educ4 mean spouse_emp mean married mean black mean hv_child mean num_child mean grade mean working mean unemp mean retired mean disabled mean student mean homemaker  mean work_paper mean worka_paper mean worku_paper mean leisure_paper mean ep_paper mean sleeping_paper mean esp_paper mean leisure_noesp_paper mean tv_paper mean otherleisure_paper mean socializing_paper mean home_paper mean homeproduction_paper mean homeown_paper mean shopping_paper mean othercare_paper mean childcare_paper mean other_paper mean education_paper mean civic_paper mean ownmedical_paper mean unclassified_paper) show(none);

tabout quarter if year==2011           [aw=weight_adj] using state_dataset_ALLUS_temp.xls, append  format(8) h1(nil) h2(nil) h3(nil) ptotal(none) lines (none)    sum cells(N work_paper mean year mean quarter mean male mean age mean age1 mean age2 mean age3 mean age4 mean age5 mean educ1 mean educ2 mean educ3 mean educ4 mean spouse_emp mean married mean black mean hv_child mean num_child mean grade mean working mean unemp mean retired mean disabled mean student mean homemaker  mean work_paper mean worka_paper mean worku_paper mean leisure_paper mean ep_paper mean sleeping_paper mean esp_paper mean leisure_noesp_paper mean tv_paper mean otherleisure_paper mean socializing_paper mean home_paper mean homeproduction_paper mean homeown_paper mean shopping_paper mean othercare_paper mean childcare_paper mean other_paper mean education_paper mean civic_paper mean ownmedical_paper mean unclassified_paper) show(none);

tabout quarter if year==2012           [aw=weight_adj] using state_dataset_ALLUS_temp.xls, append  format(8) h1(nil) h2(nil) h3(nil) ptotal(none) lines (none)    sum cells(N work_paper mean year mean quarter mean male mean age mean age1 mean age2 mean age3 mean age4 mean age5 mean educ1 mean educ2 mean educ3 mean educ4 mean spouse_emp mean married mean black mean hv_child mean num_child mean grade mean working mean unemp mean retired mean disabled mean student mean homemaker  mean work_paper mean worka_paper mean worku_paper mean leisure_paper mean ep_paper mean sleeping_paper mean esp_paper mean leisure_noesp_paper mean tv_paper mean otherleisure_paper mean socializing_paper mean home_paper mean homeproduction_paper mean homeown_paper mean shopping_paper mean othercare_paper mean childcare_paper mean other_paper mean education_paper mean civic_paper mean ownmedical_paper mean unclassified_paper) show(none);

tabout quarter if year==2013           [aw=weight_adj] using state_dataset_ALLUS_temp.xls, append  format(8) h1(nil) h2(nil) h3(nil) ptotal(none) lines (none)    sum cells(N work_paper mean year mean quarter mean male mean age mean age1 mean age2 mean age3 mean age4 mean age5 mean educ1 mean educ2 mean educ3 mean educ4 mean spouse_emp mean married mean black mean hv_child mean num_child mean grade mean working mean unemp mean retired mean disabled mean student mean homemaker  mean work_paper mean worka_paper mean worku_paper mean leisure_paper mean ep_paper mean sleeping_paper mean esp_paper mean leisure_noesp_paper mean tv_paper mean otherleisure_paper mean socializing_paper mean home_paper mean homeproduction_paper mean homeown_paper mean shopping_paper mean othercare_paper mean childcare_paper mean other_paper mean education_paper mean civic_paper mean ownmedical_paper mean unclassified_paper) show(none);

tabout quarter if year==2014           [aw=weight_adj] using state_dataset_ALLUS_temp.xls, append  format(8) h1(nil) h2(nil) h3(nil) ptotal(none) lines (none)    sum cells(N work_paper mean year mean quarter mean male mean age mean age1 mean age2 mean age3 mean age4 mean age5 mean educ1 mean educ2 mean educ3 mean educ4 mean spouse_emp mean married mean black mean hv_child mean num_child mean grade mean working mean unemp mean retired mean disabled mean student mean homemaker  mean work_paper mean worka_paper mean worku_paper mean leisure_paper mean ep_paper mean sleeping_paper mean esp_paper mean leisure_noesp_paper mean tv_paper mean otherleisure_paper mean socializing_paper mean home_paper mean homeproduction_paper mean homeown_paper mean shopping_paper mean othercare_paper mean childcare_paper mean other_paper mean education_paper mean civic_paper mean ownmedical_paper mean unclassified_paper) show(none);

tabout quarter if year==2015           [aw=weight_adj] using state_dataset_ALLUS_temp.xls, append  format(8) h1(nil) h2(nil) h3(nil) ptotal(none) lines (none)    sum cells(N work_paper mean year mean quarter mean male mean age mean age1 mean age2 mean age3 mean age4 mean age5 mean educ1 mean educ2 mean educ3 mean educ4 mean spouse_emp mean married mean black mean hv_child mean num_child mean grade mean working mean unemp mean retired mean disabled mean student mean homemaker  mean work_paper mean worka_paper mean worku_paper mean leisure_paper mean ep_paper mean sleeping_paper mean esp_paper mean leisure_noesp_paper mean tv_paper mean otherleisure_paper mean socializing_paper mean home_paper mean homeproduction_paper mean homeown_paper mean shopping_paper mean othercare_paper mean childcare_paper mean other_paper mean education_paper mean civic_paper mean ownmedical_paper mean unclassified_paper) show(none);

tabout quarter if year==2016           [aw=weight_adj] using state_dataset_ALLUS_temp.xls, append  format(8) h1(nil) h2(nil) h3(nil) ptotal(none) lines (none)    sum cells(N work_paper mean year mean quarter mean male mean age mean age1 mean age2 mean age3 mean age4 mean age5 mean educ1 mean educ2 mean educ3 mean educ4 mean spouse_emp mean married mean black mean hv_child mean num_child mean grade mean working mean unemp mean retired mean disabled mean student mean homemaker  mean work_paper mean worka_paper mean worku_paper mean leisure_paper mean ep_paper mean sleeping_paper mean esp_paper mean leisure_noesp_paper mean tv_paper mean otherleisure_paper mean socializing_paper mean home_paper mean homeproduction_paper mean homeown_paper mean shopping_paper mean othercare_paper mean childcare_paper mean other_paper mean education_paper mean civic_paper mean ownmedical_paper mean unclassified_paper) show(none);

tabout quarter if year==2017           [aw=weight_adj] using state_dataset_ALLUS_temp.xls, append  format(8) h1(nil) h2(nil) h3(nil) ptotal(none) lines (none)    sum cells(N work_paper mean year mean quarter mean male mean age mean age1 mean age2 mean age3 mean age4 mean age5 mean educ1 mean educ2 mean educ3 mean educ4 mean spouse_emp mean married mean black mean hv_child mean num_child mean grade mean working mean unemp mean retired mean disabled mean student mean homemaker  mean work_paper mean worka_paper mean worku_paper mean leisure_paper mean ep_paper mean sleeping_paper mean esp_paper mean leisure_noesp_paper mean tv_paper mean otherleisure_paper mean socializing_paper mean home_paper mean homeproduction_paper mean homeown_paper mean shopping_paper mean othercare_paper mean childcare_paper mean other_paper mean education_paper mean civic_paper mean ownmedical_paper mean unclassified_paper) show(none);

tabout quarter if year==2018           [aw=weight_adj] using state_dataset_ALLUS_temp.xls, append  format(8) h1(nil) h2(nil) h3(nil) ptotal(none) lines (none)    sum cells(N work_paper mean year mean quarter mean male mean age mean age1 mean age2 mean age3 mean age4 mean age5 mean educ1 mean educ2 mean educ3 mean educ4 mean spouse_emp mean married mean black mean hv_child mean num_child mean grade mean working mean unemp mean retired mean disabled mean student mean homemaker  mean work_paper mean worka_paper mean worku_paper mean leisure_paper mean ep_paper mean sleeping_paper mean esp_paper mean leisure_noesp_paper mean tv_paper mean otherleisure_paper mean socializing_paper mean home_paper mean homeproduction_paper mean homeown_paper mean shopping_paper mean othercare_paper mean childcare_paper mean other_paper mean education_paper mean civic_paper mean ownmedical_paper mean unclassified_paper) show(none);

tabout quarter if year==2019           [aw=weight_adj] using state_dataset_ALLUS_temp.xls, append  format(8) h1(nil) h2(nil) h3(nil) ptotal(none) lines (none)    sum cells(N work_paper mean year mean quarter mean male mean age mean age1 mean age2 mean age3 mean age4 mean age5 mean educ1 mean educ2 mean educ3 mean educ4 mean spouse_emp mean married mean black mean hv_child mean num_child mean grade mean working mean unemp mean retired mean disabled mean student mean homemaker  mean work_paper mean worka_paper mean worku_paper mean leisure_paper mean ep_paper mean sleeping_paper mean esp_paper mean leisure_noesp_paper mean tv_paper mean otherleisure_paper mean socializing_paper mean home_paper mean homeproduction_paper mean homeown_paper mean shopping_paper mean othercare_paper mean childcare_paper mean other_paper mean education_paper mean civic_paper mean ownmedical_paper mean unclassified_paper) show(none);
************************************************************************************************************;